using System;
using System.Text;
using System.Collections.Generic;

using My.IdlConverter.Core;

namespace My.IdlConverter.Com
{
    internal class ComInitializeMethodTempalte
    {
        private static StringBuilder _methodTemplate = new StringBuilder();

        static ComInitializeMethodTempalte()
        {
            _methodTemplate.AppendLine(GlobalConst.PrefixPattern+"const vtl::Cv_PTR& objDOM%TEMPLATE% = GetWrapperObj();");
            _methodTemplate.AppendLine(GlobalConst.PrefixPattern + "vtl::Cv_Interface<Iv_DOM%TEMPLATE%> pIFDOM%TEMPLATE%(objDOM%TEMPLATE%);");
            _methodTemplate.AppendLine(GlobalConst.PrefixPattern + "ATLASSERT(pIFDOM%TEMPLATE%.IsNotNull());");
            _methodTemplate.AppendLine(GlobalConst.PrefixPattern + "return pIFDOM%TEMPLATE%;");
        }

        public static StringBuilder Instantiate(string prefix,string templateName)
        {
            StringBuilder sb = new StringBuilder(_methodTemplate.ToString());
            return sb.Replace(GlobalConst.TemplatePattern, templateName)
                      .Replace(GlobalConst.PrefixPattern, prefix);
        }

        public static StringBuilder Instantiate(string templateName)
        {
            return Instantiate(GlobalConst.DefaultIndent, templateName);
        }
    }
}
